package com.leetcode.LC;

import java.util.HashMap;
import java.util.Map;

public class LC169 {
    public int majorityElement(int[] nums) {
        if (nums.length==1){
            return nums[0];
        }
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            if (map.containsKey(num)){
                map.put(num,map.get(num)+1);
                if (map.get(num)>nums.length/2){
                    return num;
                }
            }else {
                map.put(num,1);
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(new LC169().majorityElement(new int[]{3,2,3}));
    }
}
